loop in skip list

Hello Forums,

i want to get some information from a skip list , i get error in line 27 , can anyone help please ?

 

pragma runLim, 0
Module m = current
Object o
filtering off

Skip objList = create() 
for o in m do {  
 {
 Regexp Reference = regexp2 "\\[[I][t][_]+([0-9]+)\\]"
 string theText= (o."Object Text" "") (o."Object Heading" "")
 string ReferenceNumber  
 if (Reference theText) {
    ReferenceNumber  = theText[match 1]
    int iReferenceNumber = intOf realOf ReferenceNumber 
  put (objList,iReferenceNumber,o)
  }
 }
}
string absNum
string s 
for o in m do { 
s = o."status"
 if ( s != " "){
  absNum = o."Absolute Number"
  int absNum1 = intOf realOf absNum
  for iReferencNumber in objList do {
   if ( absNum1 = iReferenceNumber )
     { print absNum1 "status is ok" "\n"}
   }
  }
 }

Best regards,


Control17 - Fri Aug 18 02:45:01 EDT 2017

Re: loop in skip list
Mathias Mamsch - Fri Aug 18 05:25:11 EDT 2017

You need to use the comparsion operator: 

if ( absNum1 == iReferenceNumber ) // do not use if (a = b)

Regards, Mathias

Re: loop in skip list
Control17 - Fri Aug 18 08:03:18 EDT 2017

Mathias Mamsch - Fri Aug 18 05:25:11 EDT 2017

You need to use the comparsion operator: 

if ( absNum1 == iReferenceNumber ) // do not use if (a = b)

Regards, Mathias

thanks for reply , i do it and i get no error but my code find not the absNum1 ? my code should give me It_2 ?

 

Absno. object text status
It_2 doors ok
It_3 c++ ok
It_4 dxl [It_2]  

 

can anyone help?

Best regards ,

 

Re: loop in skip list
Mike.Scharnow - Fri Aug 18 09:11:58 EDT 2017

Control17 - Fri Aug 18 08:03:18 EDT 2017

thanks for reply , i do it and i get no error but my code find not the absNum1 ? my code should give me It_2 ?

 

Absno. object text status
It_2 doors ok
It_3 c++ ok
It_4 dxl [It_2]  

 

can anyone help?

Best regards ,

 

It is not clear to me, what "Absno." is? Is it the object identifier (the concatenation of the content of the module attribute "Prefix" and the object's "Absolute Number")? Or is it a different attribute that is manually filled by your users? If the latter is the case, you should be aware of when you use the "Absno.", when you use the "reference" and when you use the "Absolute Number". It might well be that the first object shown in your table has the "Absolute Number" 1 and the "Absno." IT_2.

Then, in your first loop you create a skip list where the key of your skip list is the number of the referenced object (well, you hope that the referencing object contains only one reference) and the value is the referencing object. So, you might have a problem when two different objects contain a reference to the same object or when one object references two other objects. You might want to rethink your data model.

In your second loop you have a loop over the skip list, but "for xx in skip" will not give the key to xx but the value(!) of the skip list's entry, so you should have something like "for oReferencing in objList". You can get the referenced key using the "key" function (see DXL manual). Finally, you have a typo: you say "for iReferencNumber in" but you use the variable iReferenc*e*Number. Search the forum on AutoDeclare  on how to detect such errors.

Re: loop in skip list
Mike.Scharnow - Fri Aug 18 11:11:14 EDT 2017

and there are some more issues.

- As "Absolute Number" is of type integer, you can declare your variable absNum of type int. Thus you do not need absNum1.

- what exactly do you want to print in line 28? The absolute Number of the object that is OK? Then you don't need most of your code. The absolute Number of your referencing object? Then you need to get it from the skip list

- As you already have the key to your skiplist in absNum, you don't need the inner loop of your second loop. You can directly access the referencing object using the "find" command, see the section about Skip Lists in DXL Reference manual

 

Re: loop in skip list
Control17 - Mon Aug 21 05:26:07 EDT 2017

Mike.Scharnow - Fri Aug 18 11:11:14 EDT 2017

and there are some more issues.

- As "Absolute Number" is of type integer, you can declare your variable absNum of type int. Thus you do not need absNum1.

- what exactly do you want to print in line 28? The absolute Number of the object that is OK? Then you don't need most of your code. The absolute Number of your referencing object? Then you need to get it from the skip list

- As you already have the key to your skiplist in absNum, you don't need the inner loop of your second loop. You can directly access the referencing object using the "find" command, see the section about Skip Lists in DXL Reference manual

 

Hello,

i really appreciate your help, yes in line 28 i want to print absolute Number of the object that is ok .

how can i use  "find" command in skiplist , is my code right ?

 

pragma runLim, 0
Module m = current
Object o
filtering off

Skip objList = create() 
for o in m do {  
 {
 Regexp Reference = regexp2 "\\[[I][t][_]+([0-9]+)\\]"
 string theText= (o."Object Text" "") (o."Object Heading" "")
 string ReferenceNumber  
 if (Reference theText) {
    ReferenceNumber  = theText[match 1]
    int iReferenceNumber = intOf realOf ReferenceNumber 
  put (objList,iReferenceNumber,o)
  }//if 
 }//Regexp
}//for
int absNum
string s 
for o in m do { 
s = o."status"
 if ( s != " "){
  absNum = o."Absolute Number"
  if find (objlist,absNum,o){
   print absNum "\n"
  }//if 
 }//if
}//for

 

 

thank u for your help ,

 

Neven

 

Re: loop in skip list
Mike.Scharnow - Mon Aug 21 06:58:48 EDT 2017

Control17 - Mon Aug 21 05:26:07 EDT 2017

Hello,

i really appreciate your help, yes in line 28 i want to print absolute Number of the object that is ok .

how can i use  "find" command in skiplist , is my code right ?

 

pragma runLim, 0
Module m = current
Object o
filtering off

Skip objList = create() 
for o in m do {  
 {
 Regexp Reference = regexp2 "\\[[I][t][_]+([0-9]+)\\]"
 string theText= (o."Object Text" "") (o."Object Heading" "")
 string ReferenceNumber  
 if (Reference theText) {
    ReferenceNumber  = theText[match 1]
    int iReferenceNumber = intOf realOf ReferenceNumber 
  put (objList,iReferenceNumber,o)
  }//if 
 }//Regexp
}//for
int absNum
string s 
for o in m do { 
s = o."status"
 if ( s != " "){
  absNum = o."Absolute Number"
  if find (objlist,absNum,o){
   print absNum "\n"
  }//if 
 }//if
}//for

 

 

thank u for your help ,

 

Neven

 

Hi Neven,

perhaps it is time to step back a bit and tell us your overall goal.

What your code currently does, is

  • for every object in the current view of the current module
    • if the content of it's "status" is not a space and this object is referenced somewhere
      • print the absolute number of this (referenced) object

What I *think* you may want to achieve is

  • for every object in the current view of the current module
    • find out whether the object mentions an other object in it's object text or object heading
      • if so, present information about the status of the referenced object in relation to the referencing object

Or perhaps

  • Find out whether there are any referenced requirements which are still under development

Depending on your need the script might look different.

Some comments on your code:

  • Are you sure that you want to test against the value " "? Not "" or "ok" or something else?
  • The "find" command will look for  a key (parameter 2) in a skip list (parameter 1) and 
    1. if found, return true, else false
    2. if found and a third parameter is given, set the variable (parameter 3) to the data of the skip list.
    • So, if you are interested in the data (in this case the first referencing object), you should use it, e.g. by printing o."Absolute Number""". But for this you should not use the variable named "o", as this is already your index variable of your loop.
    • If you are not interested in the referencing object, you should use the form find (<skip>, <key>) without the third parameter

Regards,
Mike

Re: loop in skip list
Control17 - Mon Aug 21 07:41:39 EDT 2017

Mike.Scharnow - Mon Aug 21 06:58:48 EDT 2017

Hi Neven,

perhaps it is time to step back a bit and tell us your overall goal.

What your code currently does, is

  • for every object in the current view of the current module
    • if the content of it's "status" is not a space and this object is referenced somewhere
      • print the absolute number of this (referenced) object

What I *think* you may want to achieve is

  • for every object in the current view of the current module
    • find out whether the object mentions an other object in it's object text or object heading
      • if so, present information about the status of the referenced object in relation to the referencing object

Or perhaps

  • Find out whether there are any referenced requirements which are still under development

Depending on your need the script might look different.

Some comments on your code:

  • Are you sure that you want to test against the value " "? Not "" or "ok" or something else?
  • The "find" command will look for  a key (parameter 2) in a skip list (parameter 1) and 
    1. if found, return true, else false
    2. if found and a third parameter is given, set the variable (parameter 3) to the data of the skip list.
    • So, if you are interested in the data (in this case the first referencing object), you should use it, e.g. by printing o."Absolute Number""". But for this you should not use the variable named "o", as this is already your index variable of your loop.
    • If you are not interested in the referencing object, you should use the form find (<skip>, <key>) without the third parameter

Regards,
Mike

Hi Mike,

thank u for ur reply,

My code should do following:

At first search in object text and object heading the reference "[It_ absolute no. ]" and take this absolute no. and find out whether the status ok is, in this case print the absolute no. (i mean hier 2 and 3) .

Absno. object text status
It_2 doors ok
It_3 c++ ok
It_4 dxl [It_2]
It_5 matlab[It_3]  
It_6 java[It_4]  
It_7 C  

 

Regards,

Neven

 

Re: loop in skip list
Mike.Scharnow - Mon Aug 21 07:58:33 EDT 2017

Control17 - Mon Aug 21 07:41:39 EDT 2017

Hi Mike,

thank u for ur reply,

My code should do following:

At first search in object text and object heading the reference "[It_ absolute no. ]" and take this absolute no. and find out whether the status ok is, in this case print the absolute no. (i mean hier 2 and 3) .

Absno. object text status
It_2 doors ok
It_3 c++ ok
It_4 dxl [It_2]
It_5 matlab[It_3]  
It_6 java[It_4]  
It_7 C  

 

Regards,

Neven

 

So, when you run your script on this module, the result should be

2
3

because 2 and 3 are referenced and ok and 4 is referenced but not ok?

In this case you should already have what you need if you take your code from today and make the changes:

  • line 23:
    • compare against "ok", not against a space / blank
  • line 25: 
    • remove the ,o
    • correct the spelling of objlist (->objList)
    • use correct syntax: if (...) {...

 

 

Re: loop in skip list
Control17 - Tue Aug 22 07:22:15 EDT 2017

Mike.Scharnow - Mon Aug 21 07:58:33 EDT 2017

So, when you run your script on this module, the result should be

2
3

because 2 and 3 are referenced and ok and 4 is referenced but not ok?

In this case you should already have what you need if you take your code from today and make the changes:

  • line 23:
    • compare against "ok", not against a space / blank
  • line 25: 
    • remove the ,o
    • correct the spelling of objlist (->objList)
    • use correct syntax: if (...) {...

 

 

thank you.

Regards,

Neven